Click here to return to the HDL Reference Guide. | (last edit: 24. september 2012) | ||||||||||
Access (VHDL)A data type which allows for dynamic memory allocation, equivalent to pointers in C or Pascal. Used to model large memories.The type Line in package TEXTIO is an access type. An incomplete type declaration is used to permit recursively defined data structures, e.g. linked lists. Syntaxtype NewName is access DataType; type IncompleteTypeName; PlacementThe Access Type can be placed at the below shown locations.
RulesOnly variables can be of access type, and they must point to a value allocated dynamically using new (not to another variable).An access variable is initialised to the value null. A procedure DEALLOCATE(Ptr) is implicitly defined and can be called to release the storage allocated using new. Things to rememberVHDL suffers from dangling pointers. If you copy a pointer then deallocate the memory, the copied pointer still points to the now deallocated location.SynthesisNot synthesizable.TipsCan be used to reduce the amount of memory needed to simulate a large memory by only allocating host computer memory when needed.Exampletype Link; -- Incomplete type declaration type Item is record Data: Std_logic_vector(7 downto 0); NextItem: Link; end record; type Link is access Item; variable StartOfList, Ptr: Link; -- Add item to start of list Ptr := new Item; -- Allocate storage Ptr.Data := "01010101"; Ptr.NextItem := StartOfList; -- Link item into list StartOfList := Ptr; -- Delete entire list while StartOfList /= null loop Ptr := StartOfList.NextItem; DEALLOCATE(StartOfList); StartOfList := Ptr; end loop; See AlsoNew, Type, Null, Record |